<include file="header" />

<body>
<div class="wraper">
    <div class="load">
        <img class="load-bee" src="/assets/base/repair/images/load-bee.png"/>

    </div>
    <div class="top">
        <p>
        	<a href="javascript:void(0)" class="iconfont icon-zuo fl-left"></a>
        	注册
        	<a href="{BEESCRM::U('base/center/center',array('wechat_id'=>$wechat_id))}" class="iconfont icon-shouye fl-right"></a>
        </p>
    </div>
    <div class="checkbox">
        <p class="checked" data-type="0"><span class="iconfont icon-xuanzedianjihou"></span> 账号</p>
    </div>
    <div class="contain actived">
        <p class="title">学号或工号</p>
        <p class="form-box">
            <input class="input" id="number" value="{BEESCRM:$res['number']}"/>
        </p>
        <p class="title">姓名</p>
        <p class="form-box">
            <input class="input" id="username" value="{BEESCRM:$res['username']}"/>
        </p>
    </div>
     <p class="title">手机</p>
     <p class="form-box">
         <input class="input" id="mobile" value="{BEESCRM:$res['mobile']}"/>
     </p>
     <p class="title">短号</p>
     <p class="form-box">
         <input class="input" id="short_number" value="{BEESCRM:$res['short_number']}"/>
     </p>
    <p class="title">身份选择</p>
    <p class="form-box">
    	<select id="role" class="input">
    		<option value="1">学生</option>
    		<option value="2">教职工</option>
    		<option value="3">来宾</option>
    	</select>
    </p>
     <div class="address" >
        <p class="title">办公地址</p>
        <p class="form-box">
            <input class="input" id="address" value="{BEESCRM:$res['address']}"/>
        </p>
    </div>
    <div class="school" >
        <p class="title">学校</p>
        <p class="form-box">
            <select class="select" id="school">
            	<option value="14">农林大学</option>
            </select>
        </p>
    </div>
    <div class="marginb-50"></div>
    <div class="btn-box">
    	<input type="hidden" id="register_id" value="{BEESCRM:$res['register_id']}">
        <a href="#" class="btn big" id="addAddr">提交</a>
    </div>
    <if condition="$remark">
        <include file="remark"/>
    </if>
</div>

<include file="commonJS" />
<script>

$(function(){
    var role="{BEESCRM:$res.role}";
    if(role==2){
    	$('.address').show();
    }else{
    	$('.address').hide();
    	$('#address').val('');
    }
});
$("#role").change(function () {
	var id=$('#role').val();
	if(id==2){
    	$('.address').show();
    }else{
    	$('.address').hide();
    	$('#address').val('');
    }
});

    $('#addAddr').on('click',function(){
    	var data={};
    	var verify_method = /1[3|4|5|7|8][0-9]{9}/;
    	data.mobile=$('#mobile').val();
    	data.number=$('#number').val();
    	data.username = $('#username').val();
    	data.school_id = $('#school').val();
    	data.register_id=$('#register_id').val();
    	data.role=$('#role').val();
    	data.short_number=Number($('#short_number').val());
    	data.status=0;
    	data.address=$('#address').val();
        var wechat_id={BEESCRM:$wechat_id};
        if(data.role==1 && !data.short_number){
        	$.alert('error','请输入手机短号');
        	return false;
        }
        if (!data.number || data.number.length>15) {
        	$.alert('error','请输入正确的学号或工号');
        	return false;
       	} else if (!data.username) {
       		$.alert('error','姓名不能为空');
       		return false;
        }else if(!data.mobile){
	        $.alert('error','手机号不能为空');
	        return false;
        }else if (!verify_method.test(data.mobile)) {
        	$.alert('error','请输入正确的手机号');
        	return false;
        }else if (data.short_number && (data.short_number<100000 || data.short_number>999999)){
	        $.alert('error','请输入六位的短号');
	        return false;
        }else if (!data.address && data.role==2){
	        $.alert('error','请填写办公地址');
	        return false;
        }else if (data.school_id == 0){
	        $.alert('error','请选择学校');
	        return false;
        }else {
            var json=new Object();
            json.url="{BEESCRM::U('base/center/checkReg',array('wechat_id'=>$wechat_id))}";
            json.data=data;
            json.method='post';
			$.getAjax(json, true, reload, '');
        }
    });
    function reload(){
    	setTimeout("location.href ='{BEESCRM::U('base/center/center',array('wechat_id'=>$wechat_id))}'", 2000);
	}
</script>
</body>
</html>